
$(document).ready(function () {
    setTime();
    times = setInterval(setTime, 1000);    //每隔1秒执行函数
    //剩余时间为0,自动交卷
});

function setTime() {
    var hour = parseInt(timeleft / 3600);    // 计算时
    var minutes = parseInt((timeleft % 3600) / 60);    // 计算分
    var seconds = parseInt(timeleft % 60);    // 计算秒
    hour = hour < 10 ? "0" + hour : hour;
    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
    $(".showTime").val(hour + ":" + minutes + ":" + seconds);
    timeleft--;
    if (timeleft==0) {
        //点击确定后操作
        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = "calculation";
        var examidInput = document.createElement("input");
        var paperidInput = document.createElement("input");
        var useridInput = document.createElement("input");
        examidInput.setAttribute("name", "exam_id");  // 为input对象设置name
        examidInput.setAttribute("value", examid);  // 为input对象设置value

        paperidInput.setAttribute("name", "paper_id");  // 为input对象设置name
        paperidInput.setAttribute("value", paperid);  // 为input对象设置value

        useridInput.setAttribute("name", "user_id");  // 为input对象设置name
        useridInput.setAttribute("value", userid);  // 为input对象设置value

        myForm.appendChild(examidInput);
        myForm.appendChild(paperidInput);
        myForm.appendChild(useridInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }
}
